package com.da.mybatis.service.impl;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.da.mybatis.model.Student;
import com.da.mybatis.model.condition.StudentCondition;
import com.da.mybatis.mapper.StudentMapper;
import com.da.mybatis.service.StudentService;

/**
 * Service接口实现
 *
 * @author chenlida
 * @version 1.0.0 2021-05-29
 */
@Service
@Transactional(readOnly = true)
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    private static final Logger logger = LoggerFactory.getLogger(StudentService.class);

    @Override
    public IPage<Student> findStudentByCondition(StudentCondition condition) {
        IPage<Student> page = condition.buildPage();
        QueryWrapper<Student> queryWrapper = condition.buildQueryWrapper(Student.class);
        return this.page(page, queryWrapper);
    }

    @Override
    public Student getStudentById(Integer id) {
        return this.getById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean addStudent(Student student) {
        return this.save(student);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean updateStudent(Student student) {
        return this.updateById(student);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean deleteStudentById(Integer id) {
        return this.removeById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean deleteStudentByIds(List<Integer> idList) {
        return this.removeByIds(idList);
    }
}